if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ExpensePatientCareCharges]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[ExpensePatientCareCharges]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO


/***************************************************************************
* Name:			ExpensePatientCareCharges
* Purpose:		This procedure expenses all the daily patient care charges that
*				were posted during the month.
*
* PARAMETERS
* Name				Description					
* -------------		-----------------------------------------------------------
* n/a
*
* ERRORS USED		Description
* -------------		-----------------------------------------------------
* n/a
*
* RETURN VALUE
* Value    			Description					
* --------------	------------------------------------------------------
* @_exitStatus		An exit status of either true or false
***************************************************************************/
CREATE PROCEDURE [dbo].[ExpensePatientCareCharges] 
AS 
BEGIN

	SET NOCOUNT ON

	declare @LastClosedFiscalPeriodStartDate datetime
	declare @LastClosedFiscalPeriodEndDate datetime

	-- Get the GL post date for the last close.  Compute the start of the period last closed.
	exec getRefreshDates 'gl', @LastClosedFiscalPeriodEndDate output
	set @LastClosedFiscalPeriodStartDate = dateadd(month,-1,dateadd(day,1,@LastClosedFiscalPeriodEndDate))

	-- Flag daily patient care charges as expensed.
	update e set isdaily = 0 
	from patientcareexpensedetail e 
	where IsDaily = 1 and e.postdate between @LastClosedFiscalPeriodStartDate and @LastClosedFiscalPeriodEndDate

	SET NOCOUNT OFF

END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO